Skip to content

NIFI-14472: Fix potential NPE in PutKinesisFirehose batch accumulation#11211

Merged
exceptionfactory merged 1 commit into
apache:mainfrom
rakesh-rsky:fix/NIFI-14472-kinesis-firehose-npe
May 18, 2026
Merged

NIFI-14472: Fix potential NPE in PutKinesisFirehose batch accumulation#11211
exceptionfactory merged 1 commit into
apache:mainfrom
rakesh-rsky:fix/NIFI-14472-kinesis-firehose-npe

Conversation

@rakesh-rsky
Copy link
Copy Markdown
Contributor

@rakesh-rsky rakesh-rsky commented May 6, 2026

Summary

Fixes a race condition / NPE in PutKinesisFirehose.onTrigger() where a two-step computeIfAbsent() + get() on the batch-accumulation map could return null if the entry was evicted between the two calls.

Changes

  • Collapsed the two-step lookup into a single atomic computeIfAbsent(...).add(record) call in PutKinesisFirehose.java, eliminating the window for a NullPointerException.

Testing

  • Existing unit tests pass.
  • The fix is a straightforward atomic-operation replacement with no behavioral change under normal conditions.

Fixes: https://issues.apache.org/jira/browse/NIFI-14472

@exceptionfactory
Copy link
Copy Markdown
Contributor

@rakesh-rsky It looks like the last update to this branch brought in a commit instead of rebasing, can you rebase your branch against main and force push to align with the current baseline?

Copy link
Copy Markdown
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this problem @rakesh-rsky. The core functional change appears to be correct, but the comments are unnecessary and the implementation line should be broken out into several lines for readability. If you can make that change, remove the extra commit, and rebase against the current main branch, this should be good to go.

Comment on lines +137 to +143
// Use a single computeIfAbsent().add() call so the list lookup is atomic.
// The previous two-step pattern (computeIfAbsent then a separate get()) could
// throw NullPointerException when firehoseStreamName evaluates to null via
// expression language, because get(null) returned null after the absent-key
// entry was never actually inserted. (NIFI-14472)
session.read(flowFile, in -> recordHash.computeIfAbsent(firehoseStreamName, k -> new ArrayList<>())
.add(Record.builder().data(SdkBytes.fromInputStream(in)).build()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting on the previous behavior is unnecessary and should be removed. In addition, it would be helpful to separate the callback implementation across multiple lines for readability.

@rakesh-rsky rakesh-rsky force-pushed the fix/NIFI-14472-kinesis-firehose-npe branch from 0f4ced8 to 8bf55d0 Compare May 18, 2026 12:09
Copy link
Copy Markdown
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @rakesh-rsky, the functional change looks good, but the branch still includes the unrelated change to KubernetesConfigMapStateProviderTest.

@rakesh-rsky rakesh-rsky force-pushed the fix/NIFI-14472-kinesis-firehose-npe branch from 8bf55d0 to f3a3b19 Compare May 18, 2026 17:41
…eProvider teardown

- Collapsed two-step computeIfAbsent/get into a single chained call in PutKinesisFirehose to eliminate the redundant map lookup.

- Guarded KubernetesConfigMapStateProvider.shutdown() against null kubernetesClient and logger so it is safe to call on an uninitialized provider.
@rakesh-rsky rakesh-rsky force-pushed the fix/NIFI-14472-kinesis-firehose-npe branch from f3a3b19 to d9cf185 Compare May 18, 2026 17:42
Copy link
Copy Markdown
Contributor

@exceptionfactory exceptionfactory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for making the changes @rakesh-rsky, the latest version looks good. +1 merging

@exceptionfactory exceptionfactory merged commit 4d32a45 into apache:main May 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants